/**
 * @author ZhiWen Ren
 * @version 1.0
 * @description: LeetCode-45-跳跃游戏2
 * @date 2025/7/22 9:54
 */
public class Solution45 {
    public int jump(int[] nums) {
        int n = nums.length;
        if (n == 1) return 0;
        int ans = 0;
        int i = 0;
        int temp = 0;
        while (i < n) {
            if (i + nums[i] >= n - 1) {
                return ans + 1;
            }
            int maxStep = 0;
            for (int j = i + 1; j <= nums[i] + i; j++) {
                if (nums[j] + j > maxStep) {
                    maxStep = nums[j] + j;
                    temp = j;
                }
            }
            ans++;
            i = temp;
        }
        return ans;
    }
}
